<?php
require_once ("../../config/config.php");
require_once ("../../config/constants.php");
require_once ("../../db/queries.php");
require_once ("../../common/common.php");

$entity = $_REQUEST["entity"];
$element = $_REQUEST["element"];
$count = $_REQUEST["count"];
$type = $_REQUEST["type"];

function findInDB($entity,$element,$count,$type) {
	if($type==''){
		$strQuery = "select * from cc_v1.`".$entity."` x order by x.".$element." DESC LIMIT ".$count.";";
		return generateResultSet($strQuery);
	} else {
		$strQuery = "select * from cc_v1.`".$entity."` x where entityType = '".$type."' order by x.".$element." DESC LIMIT ".$count.";";
		return generateResultSet($strQuery);
	}
}

makeQueryXML(findInDB($entity,$element,$count,$type));
?>